import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from "rxjs/operators";

@Injectable()
export class FormRepositoryService {

    constructor(private http: HttpClient) { }

    /** 仓库文书分页 */
    listRepositoryPage(params: any){
        return this.http.post('/form/api/repository/listpage', params).pipe(
            map((res:Response) => res['data'])
        );
    }

    /** 仓库文书详情 */
    loadRepoAssembliesByFormId(id : number){
        return this.http.get('/form/api/repository/assemblies?id='+id).pipe(
            map((res:Response) => res['data'])
        );
    }
    /** 仓库中的输出文书 */
    loadRepoPrintForm(id : number){
        return this.http.get('/form/api/repository/loadprintform?id='+id).pipe(
            map((res:Response) => res['data'])
        );
    }
    /** 仓库下载文书 */
    pullFromRepo(formDef : any, repoFormId:number){
        return this.http.post("/form/api/repository/pull?repoFormId="+repoFormId, formDef).pipe(
            map((res:Response) => res['data'])
        )
    }
    /** 从仓库中移除表单*/
    deleteFromRepo(id: number){
        return this.http.get('/form/api/repository/delete?id='+id).pipe(
            map((res:Response) => res['data'])
        );
    }

    /** 获取业务流程树 */
    loadBizProcTree() {
        return this.http.get('/form/api/freeflow/listbizproctree?bizId=0').pipe(
            map((res: Response) => res['data'])
        );
    }
}